package cz.gillan.housecosts.sql;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

abstract public class AbstractDbAdapter {
	private Context context;
	private SQLiteDatabase database;
	private DatabaseHelper dbHelper;
	
	public AbstractDbAdapter(Context context) {
		setContext(context);
	}
	
	public void close() {
		dbHelper.close();
	}
	
	public AbstractDbAdapter open() throws SQLException {
		setDbHelper(new DatabaseHelper(getContext()));
		setDatabase(getDbHelper().getWritableDatabase());
		return this;
	}
	
	/**
	 * @return the context
	 */
	protected Context getContext() {
		return context;
	}
	/**
	 * @param context the context to set
	 */
	protected void setContext(Context context) {
		this.context = context;
	}
	/**
	 * @return the database
	 */
	protected SQLiteDatabase getDatabase() {
		return database;
	}
	/**
	 * @param database the database to set
	 */
	protected void setDatabase(SQLiteDatabase database) {
		this.database = database;
	}
	/**
	 * @return the dbHelper
	 */
	protected DatabaseHelper getDbHelper() {
		return dbHelper;
	}
	/**
	 * @param dbHelper the dbHelper to set
	 */
	protected void setDbHelper(DatabaseHelper dbHelper) {
		this.dbHelper = dbHelper;
	}
}
